package com.kuang.controller;

import com.kuang.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
public class AjaxController {

    @RequestMapping("/t1")
    public String test(){
        return "hello";
    }


    @RequestMapping("/a1")
    public void a1(String name, HttpServletResponse response) throws IOException {
        System.out.println("a1:param=>"+name);
        if ("kuangshen".equals(name)){
            response.getWriter().print(true);
        }else {
            response.getWriter().print(false);
        }

    }




    @RequestMapping("/a2")
    public List<User> a2(){
        List<User> userListList = new ArrayList<User>();


        //添加数据
        userListList.add(new User("狂神说java",1,"男生"));
        userListList.add(new User("狂神说前端",1,"男生"));
        userListList.add(new User("狂神说运维",1,"男生"));

        return userListList;
    }




    @RequestMapping("/a3")
    public String a3(String name,String pwd){
        String msg="";
        //这些数据应该在数据库中查询
        if(name!=null){
            if ("admin".equals(name)){
                msg="OK";
            }else{
                msg="用户名有误！";
            }
        }


        if(pwd!=null){
            if ("123456".equals(pwd)){
                msg="OK";
            }else{
                msg="密码有误！";
            }
        }
        return msg;

    }

}
